package com.Earth01;
/*
* 392. 判断子序列
* */
public class Earth240719 {
    public static void main(String[] args) {
        String s = "";
        String t = "ahbgdc";
        boolean res = isSubsequence(s,t);
        System.out.println(res);
    }
    /*方式2：双指针*/
    public static boolean isSubsequence(String s, String t) {
        //n相当于慢指针，m相当于快指针
        int n = s.length(), m = t.length();
        int slow = 0, fast = 0;
        while (slow < n && fast < m) {
            if (s.charAt(slow) == t.charAt(fast)) {
                slow++;
            }
            fast++;
        }
        return slow == n;
    }
/*    方式1：正则   ------   也可以，但是超时
    public static boolean isSubsequence(String s, String t) {
        if(s.length() == 0) return true;
        boolean res = true;
        StringBuilder sb = new StringBuilder(".*");
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            sb.append(ch).append(".*");
        }
        String regex = sb.toString();
        res = t.matches(regex);
        return res;
    }*/
}
